﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common">
    <Common.Data.Converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>
    <Common.Data.Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    <Style x:Key="{x:Type local:PasswordBox}" TargetType="{x:Type local:PasswordBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:PasswordBox}">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid>
                                <TextBlock 
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                    Margin="{TemplateBinding Padding}"
                                    Style="{TemplateBinding PlaceholderStyle}"
                                    Text="{TemplateBinding Placeholder}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Text, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Inverted}"/>
                                <ItemsControl 
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    ItemsSource="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}"
                                    Margin="{TemplateBinding Padding}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding ShowPassword, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Inverted}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Border 
                                                DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:PasswordBox}}}"
                                                Padding="{Binding DotSpacing}">
                                                <Ellipse 
                                                    Fill="{Binding DotForeground}"
                                                    Height="{Binding DotSize}"
                                                    Width="{Binding DotSize}"/>
                                            </Border>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Horizontal"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </ItemsControl>
                                <ScrollViewer 
                                    x:Name="PART_ContentHost" 
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                    Margin="{TemplateBinding Padding}"
                                    Padding="0"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Grid>
                            <local:MaskedToggleButton 
                                Grid.Column="1" 
                                Focusable="False"
                                Source="pack://application:,,,/Imagin.Controls.Common;component/Images/Toggle.png" 
                                Padding="5,0" 
                                IsChecked="{Binding ShowPassword, RelativeSource={RelativeSource TemplatedParent}}" 
                                VerticalAlignment="Center" 
                                CheckedToolTip="Hide Password" 
                                UncheckedToolTip="Show Password"/>
                            <local:MaskedImage 
                                Grid.Column="2" 
                                Source="pack://application:,,,/Imagin.Controls.Common;component/Images/Help.png"
                                Padding="5,0" 
                                ToolTip="{TemplateBinding Hint}"
                                Visibility="{Binding Hint, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StringToVisibilityConverter}}"/>
                            <local:MaskedButton 
                                Grid.Column="3" 
                                x:Name="PART_EnterButton"
                                Focusable="False"
                                Source="pack://application:,,,/Imagin.Controls.Common;component/Images/NextArrow.png"
                                Padding="5,0"
                                IsEnabled="{TemplateBinding CanEnter}"
                                Visibility="{TemplateBinding ShowEnterButton, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ShowPassword" Value="False">
                            <Setter Property="Foreground" Value="Transparent"/>
                            <Setter Property="FontFamily" Value="Consolas"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>